//
// Created by 谢哲 on 2021/4/22.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<vector<int>> vdata;

    for (int i=0; i<n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        vector<int> curdata = {i+1, a, a+b+c};
        vdata.emplace_back(curdata);
    }

    sort(vdata.begin(), vdata.end(), [](const vector<int>& a, const vector<int>& b){
        return a[2]>b[2] || (a[2]==b[2]&&a[1]>b[1]) || (a[2]==b[2]&&a[1]==b[1]&&a[0]<b[0]);
    });

    int bj = min(5, int(vdata.size()));

    for (int i=0; i<bj; ++i) {
        cout << vdata[i][0] << " " << vdata[i][2] << "\n";
    }

    return 0;
}